package com.etc.admin.controller;/*
 * 文件名：com.etc.user.controller
 * 描述：
 * 作者：施明
 * 时间：2019/5/24 11:25
 */


import com.etc.entity.User;
import com.etc.entity.UserAddress;
import com.etc.service.*;
import com.etc.utils.CommonMessage;
import com.etc.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "admin.action")
public class User0Controller {
    @Autowired
    private UserService userService;
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private UserAddressService userAddressService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private FlashOrderService flashOrderService;

    /**
     * 模糊查询分页
     *
     * @param page
     * @param limit
     * @param content
     * @return
     */
    @RequestMapping(value = "listUser")
    @ResponseBody
    public PageData<User> listUser(Integer page, Integer limit, String content) {
        if (content == null) {
            content = "";
        }

        PageData<User> pd = userService.getUserByPage(page, limit, content);
        List<User> list = pd.getData();
        pd.setCode(0);
        pd.setMsg("请求成功");
        return pd;
    }


    /**
     * 禁用启用用户
     * @param userid
     * @return
     */
    @RequestMapping(value = "banUser", method = RequestMethod.POST)
    @ResponseBody
    public CommonMessage bantUser(Integer userid) {
        CommonMessage commonMessage = new CommonMessage();
        boolean flag = false;
        if (userid == 0) {

            flag = userService.banByPrimaryKey(userid);
        }else{
            flag = userService.qiByPrimaryKey(userid);
        }

        if (flag) {
            commonMessage.setMsg("操作成功");
        } else {
            commonMessage.setMsg("操作失败");
        }
        return commonMessage;

    }

    /**
     * 查询地址
     * @param userid
     * @return
     */
    @RequestMapping(value="showAddress")
    public ModelAndView showAddress(Integer userid){
        System.out.println(userid);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("admin/bAddress");
        List<UserAddress> lu = userAddressService.selectAddress(userid);
        modelAndView.addObject("lu", lu);
        return modelAndView;
    }

    /**
     * 注册总数
     * @return
     */
    @RequestMapping(value="count",method = RequestMethod.GET)

    public ModelAndView selectCountUser(){
        ModelAndView MV = new ModelAndView();
        MV.setViewName("admin/console");
        //用户注册的总数
      int u =  userService.selectCountUser();
        MV.addObject("u",u);
        //这周用户的注册数
        int q = userService.selectDay();
        MV.addObject("q",q);
        //订单总数
        int t =  ordersService.selectCountOrders();
        MV.addObject("t",t);
        //这周的订单总数
        int w =  ordersService.selectDay();
        MV.addObject("w",w);
        //秒杀商品总数量
        int z = flashOrderService.selectFlashOrder();
        MV.addObject("z",z);
        //这周秒杀的数量
        int h = flashOrderService.selectDay();
        MV.addObject("h",h);
        //总收入
        Double y = ordersService.selectOrdersalary();
        MV.addObject("y",y);
        //这周收入
        double p = ordersService.selsctAlary();
        MV.addObject("p",p);
        return MV;
    }


}
